<template>
  <div class="leaveWordUser">
    <div v-infinite-scroll="load" class="block" :infinite-scroll-disabled="loading">
      <ul class="userList">
        <li v-for="(item, index) in list" :key="index" :class="index > 0 ? 'marginT10': ''">
          <div class="avatar">
            <el-avatar :size="60">
              <img :src="item.avatarUrl" />
            </el-avatar>
          </div>
          <div class="right marginL20">
            <div class="line-height30">{{ item.userName }}</div>
            <div class="line-height30">{{ item.title }}</div>
          </div>
        </li>
      </ul>
    </div>
  </div>
</template>

<script>
import { leaveWordUser } from '@/api/users';

export default {
  name: 'LeaveWordUser',
  data () {
    return {
      loading: false,
      listQuery: {
        condition: this.$route.query.userId,
        pager: {
          page: 1,
          pageSize: 10
        }
      },
      list: [],
      total: null
    };
  },
  computed: {

  },
  watch: {},
  created () {
    this.init();
  },
  methods: {
    load () {
      if (this.list.length < this.total) {
        this.listQuery.pager.page = this.list.length - 1;
        this.getLeaveWordUser();
      }
    },

    // 用于初始化数据
    async init () {
      await this.getLeaveWordUser();
    },

    // 联系记录 - 用户
    getLeaveWordUser () {
      this.loading = true;
      leaveWordUser(this.listQuery)
        .then(res => {
          console.log('联系记录 - 用户:', res.data);
          this.list = this.list.concat(res.data.records);
          this.total = res.data.total;
          this.loading = false;
        })
        .catch(error => {
          this.loading = false;
        });
    }
  }
};
</script>

<style lang="scss" scoped>
.userList {
  li {
    display: flex;
    border-bottom: 1px solid #ccc;
    padding-bottom: 10px;
    .avatar {
      width: 60px;
    }
    .right {
      flex: 1;
      line-height: 60px;
    }
  }
}
</style>
